<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/26
 * Time: 14:14
 */

/**
 * Class Involved_UserModel
 */

class Involved_UserThirdModel extends BaseModel{

    protected $table = 'user_third';


    

    /**
     * 获取用户信息
     * @param $user_id
     * @return mixed
     * @author alice
     * @date 2016-1-26
     */
    public function getThirdUserByCh($ch, $ch_id)
    {
        return  DB::table( $this->table )
                ->select( 'user_third_id','fk_user_id','ch','ch_id','created' )
                ->where( array('ch'=>$ch, 'ch_id'=>$ch_id) )
                ->first();
    }




    /**
     * 获取密码
     * @param $params
     * @return mixed
     */
    public function getPassword($params)
    {
        return DB::table($this->table)->where('user_id',$params['user_id'])->select('password')->first();
    }


    public function GetUserId($mobile)
    {
        return DB::table($this->table)
                ->select('user_id')
                ->where('mobile', $mobile)
                ->first();
    }

    /**
     * 获取用户名
     * @param $mobile
     * @return mixed
     */
    public function GetMobile($mobile)
    {
        return DB::table($this->table)->where('mobile',$mobile)->count();
    }

    /**
     * 验证密码
     * @param $user_id
     * @param $password
     * @return mixed
     */
    public function CheckPassword($user_id, $password)
    {
        return DB::table($this->table)->where(['user_id' => $user_id, 'password' => $password])->count();
    }

    /**
     * 密码重置
     * @param $new_pass
     * @param $user_id
     * @return mixed
     */
    public function ResetPassword($new_pass, $user_id)
    {
        return DB::table($this->table)->where(['user_id' => $user_id])->update(['password' => md5($new_pass)]);
    }

    public function GetSupplierAvatar($supplier_id)
    {
        return DB::table($this->table)
                ->select('avatar')
                ->where(['user_id' => $supplier_id])
                ->first();
    }


}